clear all
close all
clc

%%

load(['round2_1.mat'])


fMap=zeros(1,128*128*48);

fit.mask=fit.mask(:);

bb=0;
for ii=1:length(fit.mask)
    if fit.mask(ii)==1
        bb=bb+1;            
        fMap(ii)=fit.f(bb);        
    end
    
    if bb == length(fit.f)
        break;
    end

end

[t1_hdr,t1{1}] = niak_read_minc([cd, '/t1/t1map_mask_resamp.mnc']);

xFOV = (1:t1_hdr.info.dimensions(2))*t1_hdr.info.voxel_size(2);
yFOV = (1:t1_hdr.info.dimensions(1))*t1_hdr.info.voxel_size(1);

figure()

% Calculate histogram data
fMap2 = reshape(fMap,128,128,48);
imagesc(yFOV,xFOV,imrotate(fMap2(:,:,20),90))
axis image
caxis([0.05 0.3]);
colorbar
set(gca, 'XTick', [], 'YTick', [])
title('F','LineWidth',4)

fMap2(fMap2>1)=0;
fMap3=imrotate_3D(fMap2,180);

f_hdr = t1_hdr;
f_hdr.file_name = 'ms_dec4_fmap.mnc';
niak_write_minc(f_hdr,fMap3);

